package site.jlopen.secret.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.hutool.core.lang.TypeReference;
import site.jlopen.secret.client.SecretClientHttp;
import site.jlopen.secret.client.SecretReqUrl;
import site.jlopen.secret.common.SecretClientResponse;
import site.jlopen.secret.common.SecretReqBaseForm;
import site.jlopen.secret.config.SecretClientProperties;
import site.jlopen.secret.model.graph.SecretGrapGroup;
import site.jlopen.secret.model.graph.SecretGraphNodeParam;
import site.jlopen.secret.model.node.SecretNodeInfoResp;
import site.jlopen.secret.service.intf.SecretGrapManage;

public class SecretGrapImpl implements SecretGrapManage {
	private final Logger logger = LoggerFactory.getLogger(getClass());

	private final SecretClientProperties clientProperties;
	
	public SecretGrapImpl(SecretClientProperties clientProperties) {
		this.clientProperties = clientProperties;
	}

	@Override
	public SecretClientResponse<List<SecretGrapGroup>> grapGroups() {
		logger.info("获取组件分组列表请求：{}");
		SecretClientHttp<List<SecretGrapGroup>> clientRequest = new SecretClientHttp<List<SecretGrapGroup>>(clientProperties);
		Map<String, Object> form = new SecretReqBaseForm<Object>()
				.appId(clientProperties.getAppId());
		SecretClientResponse<List<SecretGrapGroup>>  res = clientRequest.execute(SecretReqUrl.GRAP_GROUPS_URL, form, new TypeReference<SecretClientResponse<List<SecretGrapGroup>>>() {});
		return res;
	}

	@Override
	public SecretClientResponse<SecretGraphNodeParam> grapNodeAttr(String nodeCode) {
		logger.info("获取组件属性请求：{}", nodeCode);
		SecretClientHttp<SecretGraphNodeParam> clientRequest = new SecretClientHttp<SecretGraphNodeParam>(clientProperties);
		Map<String, Object> form = new SecretReqBaseForm<Object>().add("nodeCode", nodeCode)
				.appId(clientProperties.getAppId());
		SecretClientResponse<SecretGraphNodeParam>  res = clientRequest.execute(SecretReqUrl.GRAP_NODEATTR_URL, form, new TypeReference<SecretClientResponse<SecretGraphNodeParam>>() {});
		return res;
	}

}
